"""
@author: yqx
@file: new_石头剪刀布.py
@time: 2024/8/23 17:16
"""
import random

class Player:
    # 名字,房间号,血量
    def __init__(self,name,blood=2):
        self.name=name
        self.room_id=None
        self.blood=blood
    # 生成1,2,3.剪刀石头布
    def action(self):
        behacior=random.randint(1,3)
        return behacior

class Room:
    def __init__(self, room_id):
        self.room_id = room_id
        self.room_members = []
    # def add_player(self, player):
        # pass
    def battle(self,one,two):
        for i in range(3):
            judge(one,two)
        judge_sf(one,two)

# 进行一次划拳,胜负条件判断
def judge(one,two):
    price=one.action()-two.action()
    if price==(-1) or price==(2):
        print(one.name,"本轮输",two.name,"本轮赢")
        one.blood-=1
    elif price==0:
        print("本轮平手")
    else :  #price==(-2) or price==(1)
        print(one.__name__,"本轮赢",two.__name__,"本轮输")
        two.blood-=1
# 输赢条件判断
def judge_sf(one,two):
    if one.blood == 0:
        print(f"{one.name},赢了")
        return 0
    elif two.blood==0:
        print(f"{two.name},赢了")
        return 0
    else:
        print("平局")
        return 0
# 1. 创建房间
# 2.创建角色
# 3.将角色加入战斗
# 4.退出房间
# 5.退出
rooms={}#房间列表
players={}#角色列表
while True:
    print("1. 创建房间  2.创建角色  3.将角色加入战斗   4.退出房间  5.退出")
    choice=input("请输入你的选择")
    if choice=='1':
        room_id=random.randint(100,110)
        rooms[room_id]=Room(room_id)
        print(rooms[room_id].room_id,"已创建")
    elif choice=='2':
        name=input("输入你的名字")
        players[name] = Player(name)
        print(name,"已创建")
    elif choice=='3':
        player1=input("输入第一个玩家的名字: ")
        player2=input("输入第二个玩家的名字: ")
        vsroom=input("请输入房间号")
        if player1 in players and player2 in players and vsroom in rooms:
            player1=players[player1]
            player2=players[player2]
            room=rooms[vsroom]
            room.battle(player1,player2)
        else:
            print("输入不存在")
    elif choice=='4':
        pass
    elif choice=='5':
        break
    else:
        pass

